#!/bin/bash

if [ -a server_pid ]; then
    echo Server is running.
    exit 1
fi

cd server
nohup python3 ./main.py > server.log 2>&1 &
SERVER_PID=$!

sleep 1
ps -p $SERVER_PID > /dev/null 2>&1
if [ $? != 0 ]; then
    echo "Failed to run server."
    exit 1
fi

echo $SERVER_PID > server_pid
chmod -w server_pid